
<div id="append_parent"></div>
<div class="container" id="cpcontainer">
	<div class="itemtitle"><h3>{{if empty($cateInfo)}}新增{{else}}编辑{{/if}}分类</h3></div>
	<table class="tb tb2 ">
	<tbody>
		<tr>
			<td colspan="2" class="td27">分类名称:</td>
		</tr>
		<tr class="noborder">
			<td class="vtop rowform"><input name="name" value="{{$cateInfo.name}}" type="text" class="txt"></td>
			<td class="vtop tips2"></td>
		</tr>

		<tr>
			<td colspan="2" class="td27">父级分类id:</td>
		</tr>
		<tr class="noborder">
			<td class="vtop rowform"><input name="parent_cid" value="{{$cateInfo.parent_cid}}" type="text" class="txt"></td>
			<td class="vtop tips2">如没有上级分类，就不用填写</td>
		</tr>

		<tr>
			<td colspan="2">
				<input name="cid" value="{{$cateInfo.cid}}" type="hidden">
				<input type="button" class="btn" value="提交" id="_j_cate_edit_submit">
			</td>
		</tr>
	</tbody>
	</table>
</div>


<script>
K.App('apps/admin/ACategory.js', ['jQuery']).define(function() {

    var $ = this.require('jQuery');

    return {

		'container' : '#cpcontainer',

        'events' : {
            'click #_j_cate_edit_submit' : 'onCateEditSubmit'
        },

        'main' : function() {
        },

        'onCateEditSubmit' : function(evt) {
        	var ctx = this.getContainer(),
        		name = ctx.find(':text[name=name]').val(),
        		parent_cid = ctx.find(':text[name=parent_cid]').val(),
        		cid = ctx.find(':hidden[name=cid]').val();
        	
			// 确认
			if (!confirm('您确定提交么？')) {
				return;
			}

           	// 提交结果
           	$.ajax({
           		'url' : '/admin/ajax/cate_edit.php',
           		'data' : {'name':name, 'cid':cid, 'parent_cid':parent_cid},
           		'type' : 'POST',
           		'success' : function(data){
                    	data = $.parseJSON(data);
                    	if (data.error) {
                    		alert(data.error.errmsg);
                    	} else {
                    		ctx.find(':hidden[name=cid]').val( data.payload.cid );
                    		alert('提交成功');
                    	}
           		}
           	});
        }
    }
});
</script>